#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/1/18 13:17
# @Author  : shwy
# @Site    : http://ishwy.me
# @File    : test.py
# @Software: PyCharm
# 数据库连接性测试

# 导入MySQL驱动:
import mysql.connector
# 注意把password设为你的root口令:
conn = mysql.connector.connect(user='root', password='root', database='test', use_unicode=True)
cursor = conn.cursor()
# 创建user表:
# cursor.execute('create table user (id varchar(20) primary key, name varchar(20))')
# 插入一行记录，注意MySQL的占位符是%s:
# cursor.execute('insert into user (id, name) values ("2222","12312312312")')
cursor.execute('update user set name = "1111" WHERE id="2" ')
print (cursor.rowcount)
# 运行查询:
# cursor = conn.cursor()
# cursor.execute('select * from user where id = %s', ('1',))
# values = cursor.fetchall()
# print (values)
# 关闭Cursor和Connection:
# cursor.close()
# conn.close()